package com.ruoyi.order.mapper;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.order.domain.VO.VerificationDetail;
import com.ruoyi.order.domain.VerificationRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 核销记录Mapper接口
 * @author ruoyi
 * @date 2025-07-15
 */
public interface VerificationRecordMapper extends BaseMapper<VerificationRecord> {

    @Select("SELECT * FROM verification_record WHERE verify_code = #{verifyCode}")
    VerificationRecord selectByVerifyCode(@Param("verifyCode") String verifyCode);



    @Select("SELECT COUNT(1) FROM merchant WHERE u_id = #{userId} AND m_id = #{merchantId}")
    Boolean existsBySubMerchant(@Param("userId") Long userId, @Param("merchantId") Long merchantId);

    @Select("SELECT COUNT(1) > 0 FROM verification_record WHERE verify_code = #{code}")
    Boolean existsByVerifyCode(@Param("code")String code);

    /**
     * 插入核销记录
     * @param record
     */
    void insertRecord(VerificationRecord record);

    /**
     * 更新核销
     */
    void updateRecord(VerificationRecord record);



    VerificationRecord selectByOrderIdAndMerchantIdAndUserId(@Param("orderId")Long orderId, @Param("merchantId")Long merchantId,@Param("userId") Long userId);

    /**
     * 查询核销详情
     * @return
     */
    List<VerificationDetail> selectDetail();


    /**
     * 查询过期核销码
     */
    List<VerificationRecord> selectExpiredRecords(Date now);
}